// pages/my/my.js
const cosntantFile = require("../../utils/constant.js");
const constant = cosntantFile.constant;
const noticeFile = require("../../utils/notice.js");
const Toast = noticeFile.Toast;

Page({

  data: {
    auth: {
      root: 0,
      manager: 3,
    },
    user: {
      desc: "",
      auth: 6,
    },
    greet: "您好！",
  },

  onLoad: function (options) {

  },

  onShow: function() {
    const auth = wx.getStorageSync('auth');
    const desc = wx.getStorageSync('desc');
    let root = wx.getStorageSync('root');
    let manager = wx.getStorageSync('manager');
    if (root == undefined || root == null) {
      root = 0;
    }
    if (manager == undefined || manager == null) {
      manager = 3;
    }
    const now = new Date();
    const hour = now.getHours();
    var greet = "您好！";
    if (hour >= 5 && hour < 9) {
      greet = "早上好！记得吃早餐哦~";
    } else if (hour >= 9 && hour < 11) {
      greet = "上午好！今天也是元气满满的一天~";
    } else if (hour >= 11 && hour < 13) {
      greet = "中午好！午餐过后要午休恢复体力哦~";
    } else if (hour >= 13 && hour < 18) {
      greet = "下午好！还要继续努力哦~";
    } else if (hour >= 18 && hour < 23) {
      greet = "晚上好！今晚要好好休息~";
    } else {
      greet = "夜深了，明天再继续吧~";
    }

    this.setData({
      auth: {
        root: root,
        manager: manager,
      },
      user: {
        auth: auth,
        desc: desc,
      },
      greet: greet,
    })
  },

  myOrder: function(e) {
    const userModal = wx.getStorageSync('user');
    if (userModal == undefined || userModal == null || userModal =="") {
      wx.navigateTo({
        url: '../login/login',
      })
      return;
    }
    wx.navigateTo({
      url: './myOrder/myOrder?userModal='+userModal,
    })
  },

  myInvoice() {
    const userModal = wx.getStorageSync('user');
    if (userModal == null || userModal == undefined || userModal == "") {
      wx.navigateTo({
        url: '../login/login',
      })
      return;
    }
    wx.navigateTo({
      url: './myInvoice/myInvoice'
    })
  },

  manageMarteria() {
    const userModal = wx.getStorageSync('user');
    if (userModal == null || userModal == undefined || userModal == "") {
      wx.navigateTo({
        url: '../login/login',
      })
      return;
    }
    wx.navigateTo({
      url: './uploadItem/uploadItem',
    })
  }
})